package com.auction.controller;

import com.auction.common.core.controller.MyBaseController;
import com.auction.common.dao.bean.PageResult;
import com.auction.common.utils.ReturnResult;
import com.auction.entity.Order;
import com.auction.service.OrderService;
import com.auction.utils.PageOrder;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api")
@Api(tags = "订单管理")
public class OrderController extends MyBaseController {
    @Autowired
    private OrderService orderService;

    @PostMapping("/addOrder")
    @ApiOperation("添加订单")
    public ReturnResult addOrder(@RequestBody Order order) {
        System.out.println(order);
        int res=orderService.addOrder(order);
        return saveResult(res);
    }

    @PostMapping("/getOrders")
    @ApiOperation("订单列表")
    public ReturnResult getOrders(@RequestBody PageOrder pageOrder) {
       PageResult pageResult= orderService.queryByPage(pageOrder);
       return success("订单列表",pageResult);
    }

    @DeleteMapping("/deleteOrder")
    @ApiOperation("删除订单")
    public ReturnResult deleteOrder(int id) {
        int res = orderService.deleteOrderById(id);
        return deleteResult(res);
    }

    @PutMapping("/updateOrder")
    @ApiOperation("修改订单信息")
    public ReturnResult updateOrder(@RequestBody Order order) {
        int res = orderService.updateOrder(order);
        return updateResult(res);
    }

    @PutMapping("/updateOrderStatus")
    @ApiOperation("修改订单状态")
    public ReturnResult updateOrderStatus(@RequestBody Order order) {
        int res = orderService.updateOrderStatus(order);
        return updateResult(res);
    }
}
